{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e12db6be",
   "metadata": {},
   "source": [
    "---\n",
    "* 时间:2002/10/17 week09\n",
    "* 记录人：马梓杰\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a2383ad",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1. 用户输入\n",
    "\n",
    "> 2. 文本格式化（指输出）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfc0b518",
   "metadata": {},
   "source": [
    "## 1. 用户输入\n",
    "\n",
    "* input方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4f6cb0fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码123456\n"
     ]
    }
   ],
   "source": [
    "# 用户登陆系统\n",
    "usename = input(\"账号：\")\n",
    "password = input(\"密码\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "11ac5f25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "admin\n",
      "123456\n"
     ]
    }
   ],
   "source": [
    "print(usename)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e0e82aba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：1231\n",
      "密码：12321\n",
      "账号或密码错误，请重试\n"
     ]
    }
   ],
   "source": [
    "# 用户登陆系统 迭代1\n",
    "user01= \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "username = input(\"账号：\")\n",
    "password = input(\"密码：\") \n",
    "\n",
    "if username == user01 :\n",
    "    if password == password01:\n",
    "        print(\"账号密码正确，欢迎user01\")\n",
    "    else:\n",
    "        print(\"账号或密码错误，请重试\")\n",
    "else:\n",
    "    print(\"账号或密码错误，请重试\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "efd036c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "账号：admin\n",
      "密码：123456\n",
      "登陆成功~欢迎admin\n"
     ]
    }
   ],
   "source": [
    "# 用户登录系统 迭代2 循环！ 5分钟，加油~ for + range()  10点35分 \n",
    "\n",
    "user01 = \"admin\"\n",
    "password01 = \"123456\"\n",
    "\n",
    "for i in range(3,0,-1):\n",
    "    username = input(\"账号：\")\n",
    "    password = input(\"密码：\")\n",
    "    # 情景一：账号密码都正确\n",
    "    if user01 == username and  password01 == password:\n",
    "        print(\"登陆成功~欢迎\"+user01)\n",
    "        break # 中止循环\n",
    "    # 情景二：账号不存在或密码不正确，用户可以输入三次，三次之后1小时之后再来尝试\n",
    "    else:\n",
    "        if i>1:\n",
    "            print(\"账号不存在或密码不正确！请重新输入！您还有\"+str(i-1)+\"次尝试的机会\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确！请1小时候再来尝试\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e86e66a",
   "metadata": {},
   "source": [
    "## 2. 字符串的格式化输出\n",
    "\n",
    "> 1. 字符串的拼接\n",
    "> 2. 占位符\n",
    "> 3. 格式化输出的方法：format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b091307d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：1\n",
      "地区：1\n",
      "工作：1\n",
      "年龄：1\n",
      "期待薪资：1\n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息）\n",
    "\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''--------INFO'''+ name + '''-------\n",
    "地区：'''+ region +'''\n",
    "工作：'''+ job + '''\n",
    "年龄：'''+ age +'''\n",
    "期待薪资：'''+ salary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5f7d95a6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------INFO1-------\n",
      "地区：1\n",
      "工作：1\n",
      "年龄：1\n",
      "期待薪资：1\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7ba1e9fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：1\n",
      "地区：1\n",
      "工作：1\n",
      "年龄：1\n",
      "期待薪资：1\n",
      "---------INFO 1 --------\n",
      "地区：1 \n",
      "工作：1 \n",
      "年龄：1\n",
      "薪资期待：1 \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） : 占位符 s%\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO %s --------\n",
    "地区：%s \n",
    "工作：%s \n",
    "年龄：%s\n",
    "薪资期待：%s '''%(name,region,job,age,salary)\n",
    "print(info)\n",
    "# 局限性：有序，个数确定，不能乱写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "63f7494c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "昵称：1\n",
      "地区：1\n",
      "工作：1\n",
      "年龄：1\n",
      "期待薪资：1\n",
      "---------INFO 1 --------\n",
      "地区：1\n",
      "工作：1 \n",
      "年龄：1\n",
      "薪资期待：1 \n"
     ]
    }
   ],
   "source": [
    "# 用户的信息输入（完善信息） : format()\n",
    "name = input(\"昵称：\")\n",
    "region = input(\"地区：\")\n",
    "job = input(\"工作：\")\n",
    "age = input(\"年龄：\")\n",
    "salary = input(\"期待薪资：\")\n",
    "\n",
    "info = '''---------INFO {昵称} --------\n",
    "地区：{地区}\n",
    "工作：{工作职位} \n",
    "年龄：{年龄}\n",
    "薪资期待：{薪资} '''.format(工作职位=job,薪资=salary,昵称=name,年龄=age,地区=region)\n",
    "print(info)\n",
    "# 书写规范，字符串中的 字段 一一对应，不考虑其顺序"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "77d230ec",
   "metadata": {},
   "source": [
    "## 课后作业： \n",
    "> 1. 第二章P93 前所有项目练习（下周讲）\n",
    "> 2. 购物车项目\n",
    ">> 要求：\n",
    ">> 1. 运行程序后，让用户输入支付宝余额，然后打印我们的商品列表给用户。\n",
    ">> 2. 让用户输入商品编号进行商品的购买。\n",
    ">> 3. 用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。\n",
    ">> 4. 用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。\n",
    "\n",
    "* 温馨提示：网上有很多购物车项目(但由于很多人为了\"炫技\"，99%以上我们可能阅读不了~)## 课后作业：\n",
    "> 1. 第二章p93 前所有项目练习（下周讲）\n",
    "\n",
    "> 2.购物车项目 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d2a8a74e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "欢迎使用肯德基自助点餐服务\n",
      "请你输入你的支付宝数字余额：111111\n",
      "0 ['皮蛋瘦肉粥三件套', 13]\n",
      "1 ['雪菜笋丁鸡肉粥三件套', 10]\n",
      "2 ('生滚牛肉粥三件套', 17)\n",
      "3 ('皮蛋瘦肉粥油条三件套', 13)\n",
      "4 ('培根蛋法风烧饼咖啡三件套', 20)\n",
      "5 ('大饼卷香饼鸡扒蛋豆浆三件套', 22)\n",
      "6 ('芝士猪柳蛋帕尼尼豆浆三件套', 22)\n",
      "7 ('肯德基活力全餐周末', 26)\n",
      "8 ('芝士猪柳帕尼尼全餐', 28)\n",
      "9 ('西瓜冰红茶', 1000)\n",
      "请输入商品编号:1\n",
      "你已经将商品雪菜笋丁鸡肉粥三件套添加到了购物车，你的支付宝余额是111101\n",
      "0 ['皮蛋瘦肉粥三件套', 13]\n",
      "1 ['雪菜笋丁鸡肉粥三件套', 10]\n",
      "2 ('生滚牛肉粥三件套', 17)\n",
      "3 ('皮蛋瘦肉粥油条三件套', 13)\n",
      "4 ('培根蛋法风烧饼咖啡三件套', 20)\n",
      "5 ('大饼卷香饼鸡扒蛋豆浆三件套', 22)\n",
      "6 ('芝士猪柳蛋帕尼尼豆浆三件套', 22)\n",
      "7 ('肯德基活力全餐周末', 26)\n",
      "8 ('芝士猪柳帕尼尼全餐', 28)\n",
      "9 ('西瓜冰红茶', 1000)\n",
      "请输入商品编号:1\n",
      "你已经将商品雪菜笋丁鸡肉粥三件套添加到了购物车，你的支付宝余额是111091\n",
      "0 ['皮蛋瘦肉粥三件套', 13]\n",
      "1 ['雪菜笋丁鸡肉粥三件套', 10]\n",
      "2 ('生滚牛肉粥三件套', 17)\n",
      "3 ('皮蛋瘦肉粥油条三件套', 13)\n",
      "4 ('培根蛋法风烧饼咖啡三件套', 20)\n",
      "5 ('大饼卷香饼鸡扒蛋豆浆三件套', 22)\n",
      "6 ('芝士猪柳蛋帕尼尼豆浆三件套', 22)\n",
      "7 ('肯德基活力全餐周末', 26)\n",
      "8 ('芝士猪柳帕尼尼全餐', 28)\n",
      "9 ('西瓜冰红茶', 1000)\n",
      "请输入商品编号:1\n",
      "你已经将商品雪菜笋丁鸡肉粥三件套添加到了购物车，你的支付宝余额是111081\n",
      "0 ['皮蛋瘦肉粥三件套', 13]\n",
      "1 ['雪菜笋丁鸡肉粥三件套', 10]\n",
      "2 ('生滚牛肉粥三件套', 17)\n",
      "3 ('皮蛋瘦肉粥油条三件套', 13)\n",
      "4 ('培根蛋法风烧饼咖啡三件套', 20)\n",
      "5 ('大饼卷香饼鸡扒蛋豆浆三件套', 22)\n",
      "6 ('芝士猪柳蛋帕尼尼豆浆三件套', 22)\n",
      "7 ('肯德基活力全餐周末', 26)\n",
      "8 ('芝士猪柳帕尼尼全餐', 28)\n",
      "9 ('西瓜冰红茶', 1000)\n",
      "请输入商品编号:1\n",
      "你已经将商品雪菜笋丁鸡肉粥三件套添加到了购物车，你的支付宝余额是111071\n",
      "0 ['皮蛋瘦肉粥三件套', 13]\n",
      "1 ['雪菜笋丁鸡肉粥三件套', 10]\n",
      "2 ('生滚牛肉粥三件套', 17)\n",
      "3 ('皮蛋瘦肉粥油条三件套', 13)\n",
      "4 ('培根蛋法风烧饼咖啡三件套', 20)\n",
      "5 ('大饼卷香饼鸡扒蛋豆浆三件套', 22)\n",
      "6 ('芝士猪柳蛋帕尼尼豆浆三件套', 22)\n",
      "7 ('肯德基活力全餐周末', 26)\n",
      "8 ('芝士猪柳帕尼尼全餐', 28)\n",
      "9 ('西瓜冰红茶', 1000)\n",
      "请输入商品编号:q\n",
      "------购物车清单--------\n",
      "['雪菜笋丁鸡肉粥三件套', 10]\n",
      "['雪菜笋丁鸡肉粥三件套', 10]\n",
      "['雪菜笋丁鸡肉粥三件套', 10]\n",
      "['雪菜笋丁鸡肉粥三件套', 10]\n",
      "你的支付宝余额是111071\n"
     ]
    }
   ],
   "source": [
    "product_list = [\n",
    "['皮蛋瘦肉粥三件套', 13],\n",
    "['雪菜笋丁鸡肉粥三件套', 10],\n",
    "('生滚牛肉粥三件套', 17),\n",
    "('皮蛋瘦肉粥油条三件套', 13),\n",
    "('培根蛋法风烧饼咖啡三件套', 20),\n",
    "(\"大饼卷香饼鸡扒蛋豆浆三件套\", 22),\n",
    "(\"芝士猪柳蛋帕尼尼豆浆三件套\", 22),\n",
    "(\"肯德基活力全餐周末\", 26),\n",
    "(\"芝士猪柳帕尼尼全餐\", 28),\n",
    "(\"西瓜冰红茶\", 1000)\n",
    "]\n",
    "shopping_car = []\n",
    "print(\"欢迎使用肯德基自助点餐服务\")\n",
    "zhifubao = input(\"请你输入你的支付宝数字余额：\")\n",
    "if zhifubao.isdigit():  #检测字符串是否只由数字组成，只对0和正数有效\n",
    "    zhifubao = int(zhifubao)\n",
    "    while True:\n",
    "        for item in product_list:\n",
    "            print(product_list.index(item),item)  #返回索引值\n",
    "        choice = input(\"请输入商品编号:\")\n",
    "        if choice.isdigit():\n",
    "            choice = int(choice)\n",
    "            if choice >= 0 and choice <= 9:\n",
    "                if zhifubao >= product_list[choice][1]:\n",
    "                    zhifubao = zhifubao - product_list[choice][1]\n",
    "                    shopping_car.append(product_list[choice])\n",
    "                    # shopping_car.append([product_list[choice][0], product_list[choice][1]])\n",
    "                    # shopping_car.append(product_list[choice])\n",
    "                    print(\"你已经将商品%s添加到了购物车，你的支付宝余额是%s\" % (product_list[choice][0],zhifubao))\n",
    "                else:\n",
    "                    print(\"你的支付宝余额不足，请选择其他商品\")\n",
    "            else:\n",
    "                print(\"你选择的商品不在商品列表里面\")\n",
    "        elif choice==\"q\":\n",
    "            print(\"------购物车清单--------\")\n",
    "            for item in shopping_car:\n",
    "                print(item)\n",
    "            print(\"你的支付宝余额是%s\" % zhifubao)\n",
    "            break\n",
    "        else:\n",
    "            print(\"请你输入商品编号\")\n",
    "else:\n",
    "     print(\"请输入数字的支付宝余额\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ad3a77d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d751b6c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
